package javaweb.web;
import javaweb.pojo.Cart;
import javaweb.pojo.User;
import javaweb.servlet.impl.BaseServlet;
import javaweb.servlet.impl.OrderImplServlet;
import javaweb.utility.JDBCUnility;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
/**
 * @author shkstart
 * @creat -08-09 0:52
 */
public class OrderServlet extends BaseServlet {
    private OrderImplServlet ois = new OrderImplServlet();
    protected void createOrder(HttpServletRequest request, HttpServletResponse response) throws Exception {
        User loginUser = (User) request.getSession().getAttribute("user");
        Cart cart = (Cart) request.getSession().getAttribute("cart");
        if (loginUser == null) {
            request.getRequestDispatcher("/pages/user/login.jsp").forward(request, response);
            return;
        }
            int userId = loginUser.getId();
            String orderId = null;
            orderId = ois.createOrder(cart, userId);
        request.getSession().setAttribute("orderId", orderId);
        response.sendRedirect(request.getContextPath() + "/pages/cart/checkout.jsp");
    }
}